/**
 * @file common.h
 * Header file containing global defines.
 */

#ifndef _COMMON_H
#define _COMMON_H

#include "node.h"

/* Return codes used by the functions throughout the project */
#define P2P_OK 0
#define P2P_ERROR -1

/* Error status codes for P2P_DATA messages (see HTTP status codes) */
#define P2P_DATA_OK			200
#define P2P_DATA_ERROR			0

/*	Client error */
#define P2P_BAD_REQUEST			400
#define P2P_UNAUTHORIZED		401
#define P2P_FORBIDDEN			403
#define P2P_NOT_FOUND			404
#define P2P_GONE			400
#define P2P_REQUEST_URI_TOO_LONG	400

/*	Server error */
#define P2P_INTERNAL_SERVER_ERROR	500
#define P2P_NOT_IMPLEMENTED		500
#define P2P_SERVICE_UNAVAILABLE		503



/* Utility functions used throughout the project */
int min(int a, int b);
int max(int a, int b);
int get_tokens(const char *s, char ***tok, int (*is_delim)(int));
void free_tokens(int T, char **tok);

/* Error handling */
typedef enum _Verbosity {
	VERROR, // show errors
	VINFO, // show generic info
	VPROTO, // show protocol actions
	VMSG, // show message contents
	VSYSCL, // show system calls
	VDEBUG // debug messages
} Verbosity;

void verbose(const Node *node, int level, char *format, ...);

#endif /* _COMMON_H */
